package com.bw.day2task.mvp.presenter;


import android.content.Context;
import android.content.SharedPreferences;

import com.blankj.utilcode.util.LogUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.bw.day2task.App;
import com.bw.day2task.bean.BeanPhone;
import com.bw.day2task.bean.BeanUser;
import com.bw.day2task.bean.BeanUserlog;
import com.bw.day2task.bean.BeanVideo;
import com.bw.day2task.mvp.content.LogContent;
import com.bw.library.mvp.presenter.BasePresenter;

import org.jetbrains.annotations.NotNull;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

public class LogPresenter extends BasePresenter<LogContent.View,LogContent.Model> {

    public LogPresenter(LogContent.View mView, LogContent.Model mModel) {
        super(mView, mModel);
    }
    public void initLog(){
        mModel.requestLog(mView.getname(), mView.getpass(), new Observer<BeanUserlog>() {
            @Override
            public void onSubscribe(@NotNull Disposable d) {
                LogUtils.d("onSubscribe");
            }

            @Override
            public void onNext(@NotNull BeanUserlog beanUser) {
                String code = beanUser.getCode();
                LogUtils.d("onNext");
                mView.ShowOk();
            }

            @Override
            public void onError(@NotNull Throwable e) {
                LogUtils.d(e.getMessage());
                LogUtils.d("onError");
            }

            @Override
            public void onComplete() {
                LogUtils.d("onComplete");
            }
        });
    }
    public void initreg(){
        mModel.requestreg(mView.getname(), mView.getpass(), new Observer<BeanUser>() {
            @Override
            public void onSubscribe(@NotNull Disposable d) {

            }

            @Override
            public void onNext(@NotNull BeanUser beanUser) {
//                SharedPreferences user = App.context.getSharedPreferences("user", Context.MODE_PRIVATE);
//                SharedPreferences.Editor edit = user.edit();
//                edit.putString("token",beanUser.getResult().getToken());
//                edit.commit();
                ToastUtils.showShort(mView.getname()+"________"+mView.getpass());
                mView.ShowOk();
            }

            @Override
            public void onError(@NotNull Throwable e) {

            }

            @Override
            public void onComplete() {

            }
        });
    }
    public void initvideo(){
        mModel.requesvideo(new Observer<BeanPhone>() {
            @Override
            public void onSubscribe(@NotNull Disposable d) {
                LogUtils.d("onSubscribe");
            }

            @Override
            public void onNext(@NotNull BeanPhone beanPhone) {
                mView.ShowOk();
                LogUtils.json(beanPhone);
            }

            @Override
            public void onError(@NotNull Throwable e) {
                LogUtils.d("onError");
            }

            @Override
            public void onComplete() {
                LogUtils.d("onComplete");
            }
        });
    }
    public void initvodeo2(){
        mModel.requesvideo2(new Observer<BeanVideo>() {
            @Override
            public void onSubscribe(@NotNull Disposable d) {

            }

            @Override
            public void onNext(@NotNull BeanVideo beanVideo) {
                mView.getvideo(beanVideo);
            }

            @Override
            public void onError(@NotNull Throwable e) {

            }

            @Override
            public void onComplete() {

            }
        });
    }
}
